package com.sanchunhui.psc.presenter

import com.sanchunhui.psc.data.protocol.ResponseInfo
import com.sanchunhui.psc.ext.excute
import com.sanchunhui.psc.presenter.view.MyTeamMemberView
import com.sanchunhui.psc.presenter.view.TeamMembersView
import com.sanchunhui.psc.rx.BaseSubscriber
import com.sanchunhui.psc.service.TeamMemberService
import javax.inject.Inject

/**
 * @Author zyx
 * @Date 2021/7/21-14:40
 * @Dscribe
 */
class MyTeamMemberPresenter @Inject constructor() : BasePresenter<MyTeamMemberView>()  {

    @Inject
    lateinit var memberService : TeamMemberService

    /*
      获取登录用户role=1分组下所有成员
    */
    fun  getMyTeamMember(token:String) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        memberService.getMyTeamMember(token).excute(object : BaseSubscriber<ResponseInfo>(mView) {
            override fun onNext(t: ResponseInfo) {
                mView.onGetMyTeamMemberResult(t)
            }
        }, lifecycleProvider)
    }

    /*
      获取所在或指定分组信息
    */
    fun  getMyTeamInfo(token:String) {
        if (!checkNetWork()) {
            return
        }
        memberService.getMyTeamInfo(token).excute(object : BaseSubscriber<ResponseInfo>(mView) {
            override fun onNext(t: ResponseInfo) {
                mView.onGetMyTeamInfoResult(t)
            }
        }, lifecycleProvider)
    }

    /*
         更改分组状态
     */
    fun changeTeamStatus(teamId: Int,token: String, status:String) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        memberService.changeTeamStatus(teamId,token,status).excute(object : BaseSubscriber<ResponseInfo>(mView) {
            override fun onNext(t: ResponseInfo) {
                mView.onChangTeamStatusResult(t)
            }

        }, lifecycleProvider )
    }

}